<html>
<head><meta charset="utf-8"><title>why `exchange_free` does not exist in std library now? · t-compiler/help · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/index.html">t-compiler/help</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/why.20.60exchange_free.60.20does.20not.20exist.20in.20std.20library.20now.3F.html">why `exchange_free` does not exist in std library now?</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="226283975"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/why%20%60exchange_free%60%20does%20not%20exist%20in%20std%20library%20now%3F/near/226283975" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> sfzhu <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/why.20.60exchange_free.60.20does.20not.20exist.20in.20std.20library.20now.3F.html#226283975">(Feb 14 2021 at 03:51)</a>:</h4>
<p>I am doing some experimental changes on the compiler. I have found out how to use <code>exchange_malloc</code> to allocate memory. I am looking for how to deallocate those memory. I found an old stack overflow answer <a href="https://stackoverflow.com/a/30356213/2378484">https://stackoverflow.com/a/30356213/2378484</a> that introduces <code>exchange_free</code>. However, it does not exist in the current std library. Rather, I found <code>box_free</code>. Do they work similarly? If I want to generate some code to free the memory allocated by <code>exchange_malloc</code>, which should I use? <br>
Through some quick search, I realized I can try to monomorphize <code>box_free</code>.</p>



<a name="226293393"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/why%20%60exchange_free%60%20does%20not%20exist%20in%20std%20library%20now%3F/near/226293393" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bjorn3 <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/why.20.60exchange_free.60.20does.20not.20exist.20in.20std.20library.20now.3F.html#226293393">(Feb 14 2021 at 08:39)</a>:</h4>
<p><code>Box</code> uses <code>box_free</code> to free the allocated memory. You shouldn't use <code>exchange_malloc</code> or <code>box_free</code>. Instead use <code>std::alloc::alloc()</code> and <code>std::alloc::dealloc()</code>. <code>exchange_malloc</code> and <code>box_free</code> only exist because of the deep integration of <code>Box</code> in the compiler that exists for legacy reasons.</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>